package com.dalin.framework.common.eg;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;

public class ComputeFileMd5 {
	public static void main(String[] args) {
		long l = System.currentTimeMillis();
		//File f = new File("E:/workspace/cutedalin/src/com/dalin/common/eg/analyzexml/data.xml");
		File f = new File("E:/baidu player/痞子英雄(电影版)BD版[www.qire123.com].rmvb");
		System.out.println(getFileMD5(f));
		long l1 = System.currentTimeMillis();
		System.out.println("用时："+(l1-l));
	}

	public static String getFileMD5(File file) {
		if (!file.isFile()) {
			return null;
		}
		MessageDigest digest = null;
		FileInputStream in = null;
		byte buffer[] = new byte[1024];
		int len;
		try {
			digest = MessageDigest.getInstance("MD5");
			in = new FileInputStream(file);
			while ((len = in.read(buffer, 0, 1024)) != -1) {
				digest.update(buffer, 0, len);
			}
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		BigInteger bigInt = new BigInteger(1, digest.digest());
		return bigInt.toString(16);
	}

}
